<template>
  <div style="display: flex;">
    <div style="width:220px;">
      <el-menu
          background-color="white"
          text-color="#000"
          active-text-color="#fff"
          style="width: 100%;height: 100vh;border-width: 0"
          router unique-opened
          :default-active ="activeMenuIndex"
          @select="selectMenu"
      >
        <!-- 左侧菜单栏的顶部条 -->
        <div style="font-size: 20px; color: rgb(54, 134, 248); padding: 30px 0px; text-align: center">
          慧康e居医通管理系统
        </div>
        <el-menu-item index="/main">
          <template #title>
            <el-icon style="font-size: 20px;"><Monitor /></el-icon> &nbsp;&nbsp; <span>工作台</span>
          </template>
        </el-menu-item>
        <el-sub-menu index="2">
          <template #title>
            <el-icon style="font-size: 20px;"><EditPen /></el-icon> &nbsp;&nbsp; <span>签约管理</span>
          </template>
          <el-menu-item index="/signing">待处理签约</el-menu-item>
          <el-menu-item index="/signingRecord">签约记录</el-menu-item>
        </el-sub-menu>
<!--        <el-sub-menu index="3">-->
<!--          <template #title>-->
<!--            <el-icon style="font-size: 20px;"><Notebook /></el-icon> &nbsp;&nbsp; <span>服务管理</span>-->
<!--          </template>-->
<!--          <el-menu-item index="/service">待处理服务</el-menu-item>-->
<!--          <el-menu-item index="/serviceRecord">服务记录</el-menu-item>-->
<!--        </el-sub-menu>-->
        <el-menu-item index="/resident">
          <template #title>
            <el-icon style="font-size: 20px;"><Avatar /></el-icon> &nbsp;&nbsp; <span>居民管理</span>
          </template>
        </el-menu-item>
        <el-menu-item index="/message">
          <template #title>
            <el-icon style="font-size: 20px;"><ChatDotRound /></el-icon> &nbsp;&nbsp; <span>消息管理</span>
          </template>
        </el-menu-item>
        <el-sub-menu index="6">
          <template #title>
            <el-icon style="font-size: 20px;"><CopyDocument /></el-icon> &nbsp;&nbsp; <span>资料管理</span>
          </template>
          <el-menu-item index="/institute">机构管理</el-menu-item>
          <el-menu-item index="/doctor">医生管理</el-menu-item>
          <el-menu-item index="/disease">标签管理</el-menu-item>
          <el-menu-item index="/item">服务项目管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="7">
          <template #title>
            <el-icon style="font-size: 20px;"><Histogram /></el-icon> &nbsp;&nbsp; <span>数据统计</span>
          </template>
<!--          <el-menu-item index="/">数据概况</el-menu-item>-->
          <el-menu-item index="/">签约业绩统计</el-menu-item>
<!--          <el-menu-item index="/">服务业绩统计</el-menu-item>-->
<!--          <el-menu-item index="/">居民健康异常统计</el-menu-item>-->
<!--          <el-menu-item index="/">居民标签统计</el-menu-item>-->
<!--          <el-menu-item index="/">居民年龄统计</el-menu-item>-->
<!--          <el-menu-item index="/">居民学历统计</el-menu-item>-->
<!--          <el-menu-item index="/">居性别统计</el-menu-item>-->
        </el-sub-menu>
        <el-sub-menu index="8">
          <template #title>
            <el-icon style="font-size: 20px;"><Setting /></el-icon> &nbsp;&nbsp; <span>系统设置</span>
          </template>
          <el-menu-item index="/role">角色管理</el-menu-item>
<!--          <el-menu-item index="/">资讯管理</el-menu-item>-->
<!--          <el-menu-item index="/">药品管理</el-menu-item>-->
<!--          <el-menu-item index="/">轮播图管理</el-menu-item>-->
<!--          <el-menu-item index="/">系统公告</el-menu-item>-->
<!--          <el-menu-item index="/">协议管理</el-menu-item>-->
<!--          <el-menu-item index="/">操作日志</el-menu-item>-->
        </el-sub-menu>
      </el-menu>
    </div>
    <!-- 右侧始终为100%减去左侧菜单栏的宽度  -->
    <div style="width:calc(100% - 220px);">
      <!-- 右侧顶部条与主体内容 -->
      <el-header style="height:8vh;background-color:#fff;">
        <!-- 折叠图标与用户名选项 -->
        <div style="height:100%; display: flex; align-items: center;">
          <img src="/img/login/welcome.jpg" alt="" width="30px" height="30px">
          <div style="position:absolute; right:30px; display: flex; align-items: center;">
            <img src="/img/login/bell.png" alt="" style="margin-right: 50px;">
            <el-avatar src="/img/login/avatar.png" style="width:45px;height:45px;margin-right: 10px;"></el-avatar>
            <el-dropdown trigger="click" >
              <span style="min-width:75px;max-width:400px;font-size:20px;font-weight:bold;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
                {{ user.username ? user.username: 'xxx' }}
                <el-icon style="position:relative;top:3px;"><arrow-down/></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>重置密码</el-dropdown-item>
                  <el-dropdown-item @click="logout">退出系统</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>
      <el-main style="height:calc(100% - 8vh);padding:0;background-color:rgb(242, 247, 251);">
        <router-view/>
      </el-main>
    </div>
  </div>
</template>

<script setup>
import {onMounted, ref} from "vue";

//直接调用window对象的自定义方法getUser(),获取当前登录的用户对象
const user = ref(getUser());
//定义退出登录的方法
const logout = ()=>{
  if(confirm("您确认要退出登录吗?")){
    localStorage.removeItem('user');
    window.location.href = "/login";
    user.value = '';
  }
}

const activeMenuIndex = ref("/main");

onMounted(()=>{
  const url = window.location.href;
  let urlArrays = url.split("/");
  activeMenuIndex.value = '/' + urlArrays[urlArrays.length - 1];
})

const selectMenu = (index)=>{

}

</script>

<style scoped>
  :deep(.el-menu-item.is-active) {
    background-color: rgb(41, 132, 248);
  }
</style>